package com.aidansmeaton.weightmanager;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

/** The first activity in the app. */
public class SetUpExerciseActivity extends Activity {
	
	private RadioGroup exerciseRadio;
    
	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setup_exercise);   

        setTitle("Setup - Physical Activity");
		
		exerciseRadio = (RadioGroup) findViewById(R.id.exerciseRadio);
		int selection = getSharedPreferences("Profile", 0).getInt("Exercise", 0);
		((RadioButton)exerciseRadio.getChildAt(selection*2)).setChecked(true);
        
        // Stop keyboard popping up automatically
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
        
    }
    
    private void saveExercise(){
    	int selection = 0;
		for (int i=0; i<3; i++){
			RadioButton rb = (RadioButton) exerciseRadio.getChildAt(i*2);
			if (rb.isChecked()){
				selection = i;
				break;
			}
		}
		getSharedPreferences("Profile", 0).edit().putInt("Exercise", selection).commit();
    }
	
	public void nextClick(View v){
		finish();
		saveExercise();
		Intent setupIntent = new Intent(this, SetUpWeightTypeActivity.class);
		this.startActivity(setupIntent);
	}
	
	public void backClick(View v){
		finish();
		saveExercise();
		Intent setupIntent = new Intent(this, SetUpPersonalActivity.class);
		this.startActivity(setupIntent);
	}
	
	public void laterClick(View v){
		finish();
	}
		
}